<!--
/// 
/// MaDAson - Toolkit for Model Driven Software Development
///
/// Copyright [2006] Marcus Lankenau
/// 
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///  
///     http://www.apache.org/licenses/LICENSE-2.0
///  
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
/// 
-->
<%@ Page Language="C#" %>
<%@ Import Namespace="Madason.MetaModel" %>
<%@ Import Namespace="Madason.MetaModel.DAO" %>
<%@ Import Namespace="Madason.GenUtils" %>
package <%= Class.Namespace.FullName %>;

import java.util.*;

/**
 * <%= Class.Documentation.Replace("\n", "\n	* ") %>
 */
public class <%= Class.Name %> implements java.io.Serializable
{
<% foreach (Madason.MetaModel.Attribute attr in Class.Attributes) { %>
	<%= attr.Type.ExplicitName %> <%= attr.Name + GetInitializer(attr.Type)%>;
<% } %>
<% foreach (PersistedAssociation assoc in Class.ActiveAssociations)
   { %>
	<%= (assoc.TargetClass as Entity).PrimaryKey.Type.Name %> <%= assoc.RoleName %>;
<% } %>

	public static <%= Class.Name %> getInstance()
	{
        <% if (Class.FindValue("implementation") != null && Class.FindValue("implementation").Trim() != "") { %>
        return new <%= Class.FindValue("implementation") %>();
        <% } else { %>
        return new <%= Class.Name %>();
        <% } %>
    }


<% foreach (Madason.MetaModel.Attribute attr in Class.Attributes) { %>
    /**
     * getter for
     * <%= attr.Documentation.Replace("\n", "\n		/// ")%>
     */    
	public <%= attr.Type.ExplicitName %> <%= attr.LowercaseGetter %>() {
		return <%= attr.Name %>;
	}
	
    /**
     * setter for
     * <%= attr.Documentation.Replace("\n", "\n		/// ")%>
     */    	
	public void <%= attr.LowercaseSetter %>(<%= attr.Type.ExplicitName %> <%= attr.Name %>) {
		this.<%= attr.Name %> = <%= attr.Name %>;
	}		
	
<% } %>
<% foreach (PersistedAssociation assoc in Class.ActiveAssociations) { %>
    /**
     * getter for
     * <%= assoc.Documentation.Replace("\n", "\n		/// ")%>
     */    
	public <%= (assoc.TargetClass as Entity).PrimaryKey.Type.Name %> <%= assoc.LowercaseGetter %>() {
		return <%= assoc.Name %>;
	}
	
    /**
     * setter for
     * <%= assoc.Documentation.Replace("\n", "\n		/// ")%>
     */    	
	public void <%= assoc.LowercaseSetter %>(<%= (assoc.TargetClass as Entity).PrimaryKey.Type.Name %> <%= assoc.Name %>) {
		this.<%= assoc.Name %> = <%= assoc.Name %>;
	}		
	
<% } %>

<% foreach (Operation op in Class.Operations) {  %>		
<%   if (op.Stereotype == Stereotype.Finder) continue; %>
	/**
	 * <%= op.Name %> 
	 *
	 */
	public <%= op.ReturnType.ExplicitName %> <%= op.Name %>(<%= op.ParameterString %>)
	{

<%= ProtectedSection.GenForJava("method_" + op.Name, 2) %>
	}

<% } %>	
}

<script runat="server">
	private Entity @class;
	private ProtectedSections protectedSection;

	public ProtectedSections ProtectedSection
	{
		get { return protectedSection; }
		set { protectedSection = value; }
	}	
    

	public Entity Class
	{
		get { return @class; }
		set { @class = value; }
	}	
	
	protected string GetInitializer(Class type)
	{
		if (type.Name == "DateTime") return " = new Date()";
		else return "";
	}


	public string Abstract
	{
		get
		{
			if (Class.GetUniqueStateActions().Count > 0)
				return "abstract ";
			
			foreach (Operation op in Class.Operations)
			{
				if (op.Stereotype != Stereotype.Finder)
					return "abstract ";				
			}
			return "";
		}
		
	}
	
</script>
